package com.wfw.service.impl;

import com.wfw.mapper.ProductCategoryMapper;
import com.wfw.model.ProductCategory;
import com.wfw.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {
    @Autowired
    private ProductCategoryMapper productCategoryMapper;

    @Override
    public ProductCategory findOne(Integer categoryId) {
        return productCategoryMapper.selectByPrimaryKey(categoryId);
    }

    @Override
    public List<ProductCategory> findAll() {
        return productCategoryMapper.findAll();
    }

    @Override
    public List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList) {
        return productCategoryMapper.findByCategoryTypeIn(categoryTypeList);
    }

    @Override
    public int save(ProductCategory productCategory) {
        if (productCategory.getCategoryId()==null){
            return productCategoryMapper.insertSelective(productCategory);
        }else {
            return productCategoryMapper.updateByPrimaryKeySelective(productCategory);
        }

    }
}
